package com.kgcx.organization.controller;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.organization.domain.SuggestAddress;
import com.kgcx.organization.service.SuggestAddressService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "推荐地址接口", tags = "推荐地址接口")
@RestController
@RequestMapping("suggestAddress")
public class SuggestAddressController extends BaseController {
    @Autowired
    private SuggestAddressService suggestAddressService;

    @ApiOperation(value = "查询推荐地址", httpMethod = "GET", notes = "这是用来查询推荐地址的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "推荐地址ID", required = true, paramType = "query", dataType = "String", dataTypeClass = Long.class),
    })
    @GetMapping("getSuggestAddress")
    public ReturnData<SuggestAddress> getSuggestAddress() {
        RequestData requestData = this.getRequestData();
        SuggestAddress suggestAddress = suggestAddressService.getSuggestAddress(requestData.getLong("kid"));
        return new ReturnData<>(suggestAddress);
    }

    @ApiOperation(value = "查询推荐地址", httpMethod = "GET", notes = "这是用来查询推荐地址的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "cityId", value = "城市id", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @GetMapping("getSuggestAddressList")
    public ReturnData<List<SuggestAddress>> getSuggestAddressList() {
        RequestData requestData = this.getRequestData();
        List<SuggestAddress> suggestAddressList = suggestAddressService.getSuggestAddressList(requestData);
        return new ReturnData<>(suggestAddressList);
    }

    @ApiOperation(value = "新增推荐地址", httpMethod = "POST", notes = "这是用来新增推荐地址的接口")
    @PostMapping("addSuggestAddress")
    public ReturnData addSuggestAddress(@RequestBody SuggestAddress suggestAddress) {
        suggestAddressService.addSuggestAddress(suggestAddress);
        return new ReturnData();
    }

    @ApiOperation(value = "修改推荐地址", httpMethod = "POST", notes = "这是用来修改推荐地址的接口")
    @PostMapping("updateSuggestAddress")
    public ReturnData updateSuggestAddress(@RequestBody SuggestAddress suggestAddress) {
        suggestAddressService.updateSuggestAddress(suggestAddress);
        return new ReturnData();
    }


    @ApiOperation(value = "删除推荐地址", httpMethod = "POST", notes = "这是用来删除推荐地址的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "用户ID", required = true, paramType = "query", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping("removeSuggestAddress")
    public ReturnData removeSuggestAddress(@RequestParam Long kid) {
        suggestAddressService.removeSuggestAddress(kid);
        return new ReturnData();
    }
}
